package com.dx.mapper;

import com.dx.entity.bo.HeaderBo;
import com.dx.entity.bo.InterfaceBo;
import com.dx.entity.bo.ParamsBo;
import com.dx.entity.dto.InterfaceBoDto;
import org.apache.ibatis.annotations.*;
import org.springframework.http.HttpMethod;

import java.util.List;


@Mapper
public interface InterfaceMapper {
    @Select("select * from interface where id = #{interfaceId}")
    InterfaceBo getInterface(Long interfaceId);
    
    @Select("select * from interface_params where interface_id = #{interfaceId}")
    List<ParamsBo> getInterfaceParamsByInterfaceId(Long interfaceId);

    @Insert("insert into interface_params (interface_id, name, default_value) values (#{interfaceId}, #{name}, #{defaultValue})")
    void insertInterfaceParams(@Param("interfaceId") Long interfaceId,@Param("name") String name,@Param("defaultValue") String defaultValue);
    @Select("select * from interface_headers where interface_id = #{interfaceId}")
    List<HeaderBo> getInterfaceHeadersByInterfaceId(Long interfaceId);
    @Insert("insert into interface_headers (interface_id, name, default_value) values (#{interfaceId}, #{name}, #{defaultValue})")
    void insertInterfaceHeaders(@Param("interfaceId") Long interfaceId,@Param("name") String name,@Param("defaultValue") String defaultValue);


    @Insert("insert into interface (name, description, url, method, request_body, created_by, updated_by, created_time, updated_time) values (#{interfaceBo.name}, #{interfaceBo.description}, #{interfaceBo.url}, #{interfaceBo.method}, #{requestBody}, #{interfaceBo.createdBy}, #{interfaceBo.updatedBy}, #{interfaceBo.createdTime}, #{interfaceBo.updatedTime})")
    @Options(useGeneratedKeys = true, keyColumn = "interfaceBo.id", keyProperty = "interfaceBo.id")
    void insertInterface(@Param("interfaceBo") InterfaceBo interfaceBo, @Param("requestBody") String requestBody);


    @Delete("delete from interface_params where interface_id = #{interfaceId}")
    void deleteInterfaceParamsByInterfaceId(Long interfaceId);

    @Delete("delete from interface_headers where interface_id = #{interfaceId}")
    void deleteInterfaceHeadersByInterfaceId(Long interfaceId);

    @Delete("delete from interface where id = #{interfaceId}")
    void deleteInterface(Long interfaceId);

    @Update("update interface set name = #{name}, description = #{description}, url = #{url}, method = #{method}, request_body = #{requestBody} ,updated_by=#{updatedBy} ,updated_time=#{updatedTime} where id = #{id}")
    void updateInterface(InterfaceBo interfaceBo);

    List<InterfaceBo> list(InterfaceBo interfaceBo);

    //加入对查询字段null和''的判断

    
}
